package com.example.s.Activity.team;

import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.example.s.Activity.BaseActivity;
import com.example.s.R;
import com.example.s.adapter.InnerHolder;
import com.example.s.adapter.MyRecyclerViewAdapter;
import com.example.s.bean.TeamMember;
import com.example.s.utils.LiveDataBus;

import java.util.ArrayList;
import java.util.List;

public class TeamMemberActivity extends BaseActivity {
    private ImageView back;
    private RecyclerView rv;
    private List<TeamMember> teamMemberList = new ArrayList<>();
    private MyRecyclerViewAdapter<TeamMember> teamMemberAdapter;

    private void initView() {

        back = (ImageView) findViewById(R.id.back);
        rv = (RecyclerView) findViewById(R.id.rv);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_team_member);
        initView();

        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });



        rv.setLayoutManager(new LinearLayoutManager(this));
        rv.setAdapter(teamMemberAdapter = new MyRecyclerViewAdapter<TeamMember>(teamMemberList, R.layout.rv_team_member_item) {
            @Override
            public void handleData(InnerHolder holder, TeamMember item) {
                holder.setText(R.id.role, item.getRole() + ":" + item.getName()).setSrcResource(R.id.headPhoto, Integer.parseInt(item.getHeadPhoto()));
            }

        });
        LiveDataBus.getInstance().with("allTimeMember", List.class).observe(this, new Observer<List>() {
            @Override
            public void onChanged(List list) {
                teamMemberList.clear();
                teamMemberList.addAll(list);
                teamMemberAdapter.notifyDataSetChanged();
            }
        });
    }

}
